//turret.txt - Simple script for turrets
//Cell 0,1 - Stuff done flag. If both 0, nothing. Otherwise If non-zero, this 
//turret wont attack. If the turret is itself attacked, will set the not-attack setting back to 0.
//Cell 2,3 - Stuff done flag. If both 0, nothing. Otherwise when this is killed, set to 1.

begincreaturescript;

short i,target;
short create_count = 0;
short last_spawn,last_damage;
short summon_mess = 0;
short mess1 = 0;
short mess2 = 0;

body;

beginstate INIT_STATE;
	set_name(ME,"Agent Astoria");
	change_max_health(ME,400);
	set_boss_level(ME,2);
	last_spawn = get_current_tick();
	last_damage = get_current_tick();

	set_resistance(ME,7,90);
	
	if (gf(100,16) > 0)
		erase_char(ME);
	break;

beginstate DEAD_STATE;
	sf(101,3,1);
		sf(12,25,1);
	begin_talk_mode(45);
break;

beginstate START_STATE; 
	if ((gf(12,16) > 0) && (tick_difference(last_damage,get_current_tick()) > 0)) {
		last_damage = get_current_tick();
		damage_char(ME,500 + get_ran(1,0,200),1);
		}

	if ((num_chars_in_group(1) == 0) && (gf(12,1) == 2) && (dist_to_pc() <= 8)) {
		sf(12,1,3);
		begin_talk_mode(42);
		}

	if (who_shot_me() >= 0) {
		set_foe_target(ME,who_shot_me());
		last_spawn = get_current_tick();
		do_attack();
		set_state(3);
		}

		
	if (get_foe_target(ME,10,0)) {
		last_spawn = get_current_tick();
		do_attack();
		set_state(3);
		}
	if (am_i_doing_action() == FALSE)
		end_combat_turn();
break;

beginstate 3; // attacking
	if ((gf(12,16) > 0) && (tick_difference(last_damage,get_current_tick()) > 0)) {
		last_damage = get_current_tick();
		damage_char(ME,200 + get_ran(1,0,100),5);
		}
		
	if (target_ok() == FALSE)
		set_state(START_STATE);
	
	if ((get_attitude(ME) < 10) && (num_chars_in_group(1) > 0)) {
		if ((tick_difference(last_spawn,get_current_tick()) > 0) && (mess1 == 0)) {
			last_spawn = get_current_tick();
			mess1 = 1;
			print_str_color("Astoria issues a command to the pylons. They begin to charge up ...",2);
			sf(10,27,1);
			sf(10,28,1);
			begin_talk_mode(40);
			}
		
		}
		else if (get_attitude(ME) >= 10) {
			if (gf(10,27) == 0) {
				run_char_animation(2,1,50);	
				print_str_color("Astoria issues a command to the pylons. They begin to charge up ...",2);
				sf(10,27,1);
				sf(10,28,1);
				end();
				}
			}
			
	if ((get_attitude(ME) >= 10) && (char_ok(14) == FALSE)) {
		print_named_str(ME,"calls forth a creation!");
		spawn_creature(6);
		set_summon_level(14,1);
		place_particle_num(14,10,7,10);
		run_char_animation(2,1,50);	
		pc_heard_sound_delay(136,100);						
		last_spawn = get_current_tick();
		end();
		}
	if ((tick_difference(last_spawn,get_current_tick()) > 1) && (get_attitude(ME) >= 10) && (char_ok(14))) {
		  	place_particle_num(ME,1,4,8);
			print_named_str(ME,"surrounds herself with an aura of power.");
			pc_heard_sound_delay(179,250);						
	  		create_missile_spiral(147,40,6,2);
	  		
	  		damage_nearby(150 + get_ran(1,0,40),6,1,0);
			status_nearby(-10,6,0,0);
			status_nearby(-10,6,8,0);

			last_spawn = get_current_tick();
			end();
			
			}

	do_attack();

break;

beginstate TALKING_STATE;
	if (gf(12,1) < 2)
		print_str_color("Talking: Astoria is talking to a diplomat right now.",2);
	else if (num_chars_in_group(1) > 0)
		print_str_color("Talking: Astoria is currently distracted by her assassins.",2);
	//else if (gf(100,2) == 3) {
		//print_str_color("Talking: Astoria refuses to speak with you. //Fortunately, ",2);
		//print_str_color("  with effort, she keeps from killing you.",2);
	//	}
		else begin_talk_mode(70);
break;